﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharacterState : MonoBehaviour {

	protected Animator m_Animator;
	string nowState;

	enum State {
		Grounded,
		Running,
		Jumping,
		JumpFix,
		Crouching,
		Pulling,
		Climb,
		Falling,
	}

	bool grounded;
	bool running;
	bool jumping;
	bool jumpFix;
	bool crouching;
	bool pulling;
	bool climb;
	bool falling;

	public bool Grounded {
		get => grounded;
		set {
			grounded = value;
			if (value == true)
				nowState = State.Grounded.ToString();
		}
	}
	public bool Running {
		get => running;
		set {
			running = value;
			if (value == true)
				nowState = State.Running.ToString();
		}
	}

	public bool Jumping { 
		get => jumping;
		set {
			jumping = value;
			if (value == true)
				nowState = State.Jumping.ToString();
		}

	}
	public bool JumpFix { 
		get => jumpFix;
		set {
			jumpFix = value;
			if (value == true)
				nowState = State.JumpFix.ToString();
		}
	}
	public bool Crouching { 
		get => crouching;
		set {
			crouching = value;
			if (value == true)
				nowState = State.Crouching.ToString();
		}
	}
	public bool Pulling { 
		get => pulling;
		set {
			pulling = value;
			if (value == true)
				nowState = State.Pulling.ToString();
		}
	}
	public bool Climb { 
		get => climb;
		set {
			climb = value;
			if (value == true)
				nowState = State.Climb.ToString();
		}
	}
	public bool Falling { 
		get => falling;
		set {
			falling = value;
			if (value == true)
				nowState = State.Falling.ToString();
		}
	}

	virtual protected void Awake() {
		m_Animator = gameObject.GetComponent<Animator>();
	}

	public void PlayAnim(bool play) {
		m_Animator.SetBool(nowState, play);
	}

	public void OnFallingOver() {
		Falling = false;
		m_Animator.SetBool("Falling", false);
	}

}
